package daily.kou2022_0104;

public class Num82_83 {
    //82. 删除排序链表中的重复元素 II
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode dummy = new ListNode(0, head);
        ListNode prev = dummy;
        ListNode cur=null;
        while (prev.next!=null){
            cur=prev.next;
            while (cur.next!=null&&prev.next.val==cur.next.val){
                cur=cur.next;
            }
            if(prev.next==cur){
                prev=cur;
            }else {
                prev.next=cur.next;
            }
        }
        return dummy.next;
    }




    //83. 删除排序链表中的重复元素

    public ListNode deleteDuplicates1(ListNode head) {
        if(head==null)return null;
        ListNode prev=head;
        ListNode cur=null;
        while(prev!=null&&prev.next!=null){
            cur=prev.next;
            while (cur!=null&&prev.val==cur.val){
                cur=cur.next;
            }
            prev.next=cur;
            prev=cur;
        }

        return head;
    }

}
